package com.mifengs.mall.floor;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.annotation.ItemProviderTag;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.mifengs.mall.R;
import com.mifengs.mall.adapter.TwoFourItemAdapter;
import com.mifengs.mall.entity.AdvertBean;
import com.mifengs.mall.entity.FloorBean;
import com.mifengs.mall.util.ImageLoadUtil;
import com.mifengs.mall.util.ToIntentUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lynn on 2018/4/19.
 */
@ItemProviderTag(
        viewType = FloorListAdapter.TYPE_TEN,
        layout = R.layout.fragment_two_four_flo
)
public class FloorTenItemProvider extends BaseItemProvider<FloorBean,BaseViewHolder> {
    private TwoFourItemAdapter mTwoFourItemAdapter;
    @Override
    public void convert(BaseViewHolder viewHolder, final FloorBean floorBean, int index) {
         RecyclerView mRecyclerView = viewHolder.getView(R.id.discount_list);
        ImageView five_floor_one_img = viewHolder.getView(R.id.five_floor_one_img);
        ImageView five_floor_two_img = viewHolder.getView(R.id.five_floor_two_img);
        if(floorBean !=null){
            for(int i = 0;i<floorBean.getAdverts().size();i++ ){
                AdvertBean adverts = floorBean.getAdverts().get(i);
                switch (i){
                    case 0:
                        ImageLoadUtil.displayImage(mContext,adverts.getImg(),five_floor_one_img);
                        break;
                    case 1:
                        ImageLoadUtil.displayImage(mContext,adverts.getImg(),five_floor_two_img);
                        break;
                }
            }

            five_floor_one_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AdvertBean adverts = floorBean.getAdverts().get(0);
                    ToIntentUtil.toCommonIntent(adverts.getActionUrl(),mContext);
                }
            });
            five_floor_two_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AdvertBean adverts = floorBean.getAdverts().get(1);
                    ToIntentUtil.toCommonIntent(adverts.getActionUrl(),mContext);
                }
            });

            List<AdvertBean> tempAdvertBeanList = floorBean.getAdverts();
            final List<AdvertBean> advertBeanList = new ArrayList<AdvertBean>();
            for(int i =2;i<tempAdvertBeanList.size();i++){
                AdvertBean advertBean = tempAdvertBeanList.get(i);
                advertBeanList.add(advertBean);
            }
//            mRecyclerView.addItemDecoration(new DividerGridItemDecoration(mContext));
            mRecyclerView.setLayoutManager(new GridLayoutManager(mContext,2));
            mRecyclerView.setNestedScrollingEnabled(false);
            mTwoFourItemAdapter= new TwoFourItemAdapter(R.layout.item_two_four_floor,advertBeanList,mContext,0);
            mRecyclerView.setAdapter(mTwoFourItemAdapter);
            mTwoFourItemAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    AdvertBean adverts = advertBeanList.get(position);
                    ToIntentUtil.toCommonIntent(adverts.getActionUrl(),mContext);
                }
            });
        }
    }

    @Override
    public void onClick(BaseViewHolder baseViewHolder, FloorBean floorBean, int i) {

    }

    @Override
    public boolean onLongClick(BaseViewHolder baseViewHolder, FloorBean floorBean, int i) {
        return false;
    }
}
